const app = getApp();
Page({
	data: {
		url: app.globalData.host,

		list: {},
		radio: 'r2',
	},
	onLoad: function (options) {
		wx.setNavigationBarTitle({
			title: '确认订单'
		})
		this.setData({
			id: options.id
		})
		this.getList();
	},
	getList(){
		let id = this.data.id;
		wx.showLoading({title: '加载中…'});
		app.request({
			url: '/app/order/' + id,
			method: 'GET',
			success: res => {
				this.setData({
					list: res.data
				})
			}
		})
		wx.hideLoading();
	},
	// 切换支付方式
	radioChange(e){
		this.setData({
			radio: e.detail.value
		})
	},
	pay(){
		let id = this.data.id;
		let payType = "wechat";
		wx.showLoading({title: '加载中…'});
		app.request({
			url: '/app/order/pay',
			method: 'POST',
			data: {
				id: id,
				payType: payType
			},
			success: res => {
				wx.requestPayment({
					"timeStamp": res.data.timeStamp,
					"nonceStr": res.data.nonceStr,
					"package": res.data.package,
					"signType": res.data.signType,
					"paySign": res.data.paySign,
					success: ret => {
						console.log('支付成功');
						wx.switchTab({
							url: '../../order/order'
						})
					},
					"fail":function(err){
						console.log("err",err)
					},
					"complete":function(com){
						console.log("com",com)
					}
				})
			},
		})
		wx.hideLoading();
	}
})
